<template>
    <div>
        <a-popover title="二维码批量操作" trigger="click">
            <template slot="content">
                <a-space>
                    <a-button type="primary" :loading="generateLoading" @click="handClick('generate')">批量生成</a-button>
                    <a-button type="primary" :loading="downLoading" @click="handClick('down')">批量下载</a-button>
                </a-space>
            </template>
            <a-button>二维码</a-button>
        </a-popover>
    </div>
</template>
<script>
import qs from "qs";
export default {
    name: 'CodeOptions',
    props: {
        aParams: {
            type: Object,
        },
        onCallBack: {
            type: Function,
            default: () => { }
        }
    },
    data() {
        return {
            downLoading: false,
            generateLoading: false,
        }
    },
    methods: {
        handClick(type) {
            let url;
            let params = {
                ...this.aParams,
            };
            if (type == 'down') {
                this[`${type}Loading`] = true;
                url = this.$batchDownloadQRcode;
                let str = qs.stringify(params);
                window.location.href = `${url}?${str}`;
                setTimeout(() => {
                    this[`${type}Loading`] = false;
                }, 1500)
            } else if (type == 'generate') {
                url = this.$batchCreateQRcode
                this[`${type}Loading`] = true;
                this.postAxios(url, params).then((res) => {
                    if (type == 'generate') {
                        this.$message.success({
                            content: res.msg || res.data,
                            duration: 2.5,
                        });
                        this.onCallBack();
                    }
                }).catch(() => {
                }).finally(() => {
                    this[`${type}Loading`] = false;
                })
            }

        }
    }
}
</script>
<style lang="less" scoped></style>